//服务器地址
import {server} from '../../config/index.js';
import {isAppIos} from './index';

castapp.init();

// 处理socket事件的
function Socket(){
    var userInfo = localStorage.getItem('userInfo');
    userInfo = userInfo? JSON.parse(userInfo): userInfo;

    var socket = io.connect(server);

    //连接
    socket.on('connect', ()=>{
        socket.emit('login', userInfo.nickname);
    });

    socket.on('userExists', ()=>{
        castapp.prompt('用户已在别处登录');
        if(isAppIos()){
            castapp.newInterface({
                url: './html/login.html'
            });
        }else{
            castapp.newInterface({
                url: '../html/login.html'
            });
        }
    });

    //登录成功
    socket.on('loginSuccess', ()=>{
        castapp.prompt('登录成功');
    });

}
Socket();